﻿using System;
using System.Web;
using System.Web.UI;
using SAS.Bussiness;
using SAS.Core.Entity;

namespace SAS.WebSite
{
    public partial class Default : Page
    {
        public new User User
        {
            get
            {
                if (HttpContext.Current.Session["User"] == null)
                {
                    User = new User();
                }

                return (User) HttpContext.Current.Session["User"];
            }

            set { HttpContext.Current.Session["User"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //User must be not null active and Token is not null and empty.
            if (User != null && User.IsActive && !String.IsNullOrEmpty(User.TokenKey))
            {
                UserBO userBO = new UserBO();
                if (userBO.ValidateToken(User).Result)
                {
                    Response.Redirect("~/Pages/Workspace.aspx");
                }
            }
        }
    }
}
